package com.example.sportgoods.controller;

import com.example.sportgoods.Service.LogisticsService;

import com.example.sportgoods.domain.Logistics;
import com.example.sportgoods.util.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "物流管理(0528王雪伊)")
@RestController
@RequestMapping("/logistics")
public class LogisticsController {

    @Autowired
    private LogisticsService logisticsService;

    // 获取所有物流信息列表的接口
    @ApiOperation(value = "取得所有物流信息列表", notes = "调用此接口可获取所有物流信息的列表")
    @GetMapping("/list")
    private AjaxResult list() {
        List<Logistics> allLogistics = logisticsService.selectAllLogistics();
        return AjaxResult.success(allLogistics);
    }

    // 根据id查询具体物流信息的接口
    @ApiOperation(value = "根据id查询物流信息", notes = "通过传入物流信息的唯一id，查询对应的物流详细信息")
    @ApiImplicitParam(name = "id", value = "物流信息的id", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(logisticsService.selectLogisticsById(id));
    }
    // 修改物流信息的接口
    @ApiOperation("修改物流信息")
    @PutMapping
    public AjaxResult edit(@RequestBody Logistics logistics) {
        return AjaxResult.success(logisticsService.updateLogistics(logistics));
    }

    // 新增物流的接口
    @ApiOperation("新增物流信息")
    @PostMapping
    public AjaxResult add(@RequestBody Logistics logistics) {
        logisticsService.addLogistics(logistics);
        return AjaxResult.success("物流新增成功");
    }

    // 根据物流id删除订单的接口
    @ApiOperation("根据id删除物流信息")
    @ApiImplicitParam(name = "id", value = "物流id", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id) {
        logisticsService.deleteLogisticsById(id);
        return AjaxResult.success("订单删除成功");
    }
}